import StoreModel from '@/common/model/Store'

/**
 * 获取支付宝小程序设置 (全部)
 */
const data = () => {
  return new Promise((resolve, reject) => {
    StoreModel.data().then(data => {
      resolve(data.clientData.aliapp.setting ? data.clientData.aliapp.setting : [])
    })
  })
}

// 获取支付宝小程序设置 (指定项)
const item = (key) => {
  return new Promise((resolve, reject) => {
    data().then(setting => resolve(setting[key]))
  })
}

// 是否显示客服按钮 (仅在支付宝小程序中显示)
const isShowCustomerBtn = async () => {
  const setting = await item('customer', true)
  return setting.enabled
}

export default {
  data,
  item,
  isShowCustomerBtn
}